Micron Document
`:top
In computing based on the `F33f`_`[Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f Platform, `!JavaBeans`! is a technology developed by `F33f`_`[Sun Microsystems`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sun_Microsystems]`_`f and released in 1996, as part of `F33f`_`[JDK`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Development_Kit]`_`f 1.1.

The 'beans' of JavaBeans are classes that encapsulate one or more `F33f`_`[objects`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object_(computer_science)]`_`f into a single standardized object (the bean). This standardization allows the beans to be handled in a more generic fashion, allowing easier `F33f`_`[code reuse`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Code_reuse]`_`f and `F33f`_`[introspection`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Type_introspection]`_`f. This in turn allows the beans to be treated as `F33f`_`[software components`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Component-based_software_engineering]`_`f, and to be manipulated visually by `F33f`_`[editors and IDEs`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Integrated_development_environment]`_`f without needing any initial configuration, or to know any internal implementation details.

As part of the standardization, all beans must be `F33f`_`[serializable`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Serialization]`_`f, have a `F33f`_`[zero-argument constructor`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Nullary_constructor]`_`f, and allow access to properties using `F33f`_`[getter and setter methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Mutator_method]`_`f.

>>Contents

• `F0af`_`[Features`#features]`_`f
• `F0af`_`[Advantages`#advantages]`_`f
• `F0af`_`[Disadvantages`#disadvantages]`_`f
• `F0af`_`[JavaBeans API`#javabeans-api]`_`f
• `F0af`_`[JavaBean conventions`#javabean-conventions]`_`f
• `F0af`_`[Code example`#code-example]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[External links`#external-links]`_`f

-─

>>Features

`!Introspection`!
Introspection is a process of analyzing a Bean to determine its capabilities. This is an essential feature of the Java Beans specification because it allows another application, such as a design tool, to obtain information about a component.
`!Properties`!
A property is a subset of a Bean's state. The values assigned to the properties determine the behaviour and appearance of that component. They are set through a setter method and can be obtained by a getter method.
`!Customization`!
A customizer can provide a step-by-step guide that the process must follow to use the component in a specific context.
`!Events`!
Beans may interact with the EventObject EventListener model.
`!Persistence`!
Persistence is the ability to save the current state of a Bean, including the values of a Bean's properties and instance variables, to nonvolatile storage and to retrieve them at a later time.
`!Methods`!
A Bean should use `F33f`_`[accessor methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Mutator_method]`_`f to `F33f`_`[encapsulate`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Encapsulation_(computer_programming)]`_`f the properties. A Bean can provide other methods for business logic not related to the access to the properties.

>>Advantages

• The properties, events, and methods of a bean can be exposed to another application.
• A bean may register to receive events from other objects and can generate events that are sent to those other objects.
• Auxiliary software can be provided to help configure a bean.
• The configuration settings of a bean can be saved to persistent storage and restored.

>>Disadvantages

• A class with a `F33f`_`[zero-argument constructor`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Nullary_constructor]`_`f is subject to being instantiated in an invalid state.`:cite-ref-bloch-1-0[`F5bf`_`[1`#cite-note-bloch-1]`_`f] If such a class is instantiated manually by a developer (rather than automatically by some kind of framework), the developer might not realize that the class has been improperly instantiated. The compiler cannot detect such a problem, and even if it is documented, there is no guarantee that the developer will see the documentation.
• JavaBeans are inherently mutable and so lack the advantages offered by `F33f`_`[immutable objects`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Immutable_objects]`_`f.`:cite-ref-bloch-1-1[`F5bf`_`[1`#cite-note-bloch-1]`_`f]
• Having to create getters for every property and setters for many, most, or all of them can lead to an immense quantity of `F33f`_`[boilerplate code`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Boilerplate_code]`_`f.

>>JavaBeans API

The JavaBeans functionality is provided by a set of classes and interfaces in the `B100`F9d9java.beans`f`b package.

`t
| Interface | Description |
|---|---|
| AppletInitializer | Methods in this interface are used to initialize Beans that are also applets . |
| BeanInfo | This interface allows the designer to specify information about the events, methods and properties of a Bean. |
| Customizer | This interface allows the designer to provide a graphical user interface through which a bean may be configured. |
| DesignMode | Methods in this interface determine if a bean is executing in design mode. |
| ExceptionListener | A method in this interface is invoked when an exception has occurred. |
| PropertyChangeListener | A method in this interface is invoked when a bound property is changed. |
| PropertyEditor | Objects that implement this interface allow the designer to change and display property values. |
| VetoableChangeListener | A method in this interface is invoked when a Constrained property is changed. |
| Visibility | Methods in this interface allow a bean to execute in environments where the GUI is not available. |
`t

>>JavaBean conventions

In order to function as a JavaBean `F33f`_`[class`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Class_(computer_science)]`_`f, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect Java Beans.

The required conventions are as follows:

• The class must have a public `F33f`_`[default constructor`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Default_constructor]`_`f (with no arguments). This allows easy instantiation within editing and activation frameworks.
• The class `F33f`_`[properties`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Property_(programming)]`_`f must be accessible using `*get`*, `*set`*, `*is`* (can be used for boolean properties instead of get), `*to`* and other methods (so-called `F33f`_`[accessor methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Accessor]`_`f and `F33f`_`[mutator methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Mutator_method]`_`f) according to a standard `F33f`_`[naming convention`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Naming_conventions_(programming)]`_`f. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more arguments.
• The class should be `F33f`_`[serializable`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Serialization]`_`f. (This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the `F33f`_`[VM`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Virtual_machine]`_`f and of the platform.)

>>>Code example

`B100`F9d9package player;`f`b
`B100`F9d9`f`b
`B100`F9d9public class PersonBean implements java.io.Serializable {`f`b
`B100`F9d9`f`b
`B100`F9d9 /** Properties **/`f`b
`B100`F9d9 private boolean deceased = false;`f`b
`B100`F9d9`f`b
`B100`F9d9 private List list;`f`b
`B100`F9d9`f`b
`B100`F9d9 /** Property "name", readable/writable. */`f`b
`B100`F9d9 private String name = null;`f`b
`B100`F9d9`f`b
`B100`F9d9 /** No-arg constructor (takes no arguments). */`f`b
`B100`F9d9 public PersonBean() {`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public List getList() {`f`b
`B100`F9d9 return list;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public void setList(final List list) {`f`b
`B100`F9d9 this.list = list;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 /**`f`b
`B100`F9d9 * Getter for property "name".`f`b
`B100`F9d9 */`f`b
`B100`F9d9 public String getName() {`f`b
`B100`F9d9 return name;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 /**`f`b
`B100`F9d9 * Setter for property "name".`f`b
`B100`F9d9 *`f`b
`B100`F9d9 * @param value`f`b
`B100`F9d9 */`f`b
`B100`F9d9 public void setName(final String value) {`f`b
`B100`F9d9 this.name = value;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 /**`f`b
`B100`F9d9 * Getter for property "deceased"`f`b
`B100`F9d9 * Different syntax for a boolean field (is vs get)`f`b
`B100`F9d9 */`f`b
`B100`F9d9 public boolean isDeceased() {`f`b
`B100`F9d9 return deceased;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 /**`f`b
`B100`F9d9 * Setter for property "deceased".`f`b
`B100`F9d9 * @param value`f`b
`B100`F9d9 */`f`b
`B100`F9d9 public void setDeceased(boolean value) {`f`b
`B100`F9d9 deceased = value;`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

`!`B100`F9d9TestPersonBean.java`f`b`!:

`B100`F9d9import player.PersonBean;`f`b
`B100`F9d9`f`b
`B100`F9d9/**`f`b
`B100`F9d9 * Class "TestPersonBean".`f`b
`B100`F9d9 */`f`b
`B100`F9d9public class TestPersonBean {`f`b
`B100`F9d9 /**`f`b
`B100`F9d9 * Tester method "main" for class "PersonBean".`f`b
`B100`F9d9 *`f`b
`B100`F9d9 * @param arguments`f`b
`B100`F9d9 */`f`b
`B100`F9d9 public static void main(final String[] arguments) {`f`b
`B100`F9d9 final PersonBean person = new PersonBean();`f`b
`B100`F9d9`f`b
`B100`F9d9 person.setName("Bob");`f`b
`B100`F9d9 person.setDeceased(false);`f`b
`B100`F9d9 person.setList(new ArrayList());`f`b
`B100`F9d9`f`b
`B100`F9d9 // Output: "Bob [alive]"`f`b
`B100`F9d9 System.out.print(person.getName());`f`b
`B100`F9d9 System.out.println(person.isDeceased() ? " [deceased]" : " [alive]");`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

`B100`F9d9<jsp:useBean id="person" class="player.PersonBean" scope="page"/>`f`b
`B100`F9d9<jsp:setProperty name="person" property="*"/>`f`b
`B100`F9d9`f`b
`B100`F9d9<html>`f`b
`B100`F9d9 <body>`f`b
`B100`F9d9 Name: <jsp:getProperty name="person" property="name"/><br/>`f`b
`B100`F9d9 Deceased? <jsp:getProperty name="person" property="deceased"/><br/>`f`b
`B100`F9d9 <br/>`f`b
`B100`F9d9 <form name="beanTest" method="POST" action="testPersonBean.jsp">`f`b
`B100`F9d9 Enter a name: <input type="text" name="name" size="50"><br/>`f`b
`B100`F9d9 Choose an option:`f`b
`B100`F9d9 <select name="deceased">`f`b
`B100`F9d9 <option value="false">Alive</option>`f`b
`B100`F9d9 <option value="true">Dead</option>`f`b
`B100`F9d9 </select>`f`b
`B100`F9d9 <input type="submit" value="Test the Bean">`f`b
`B100`F9d9 </form>`f`b
`B100`F9d9 </body>`f`b
`B100`F9d9</html>`f`b

>>See also

• `F33f`_`[Software packaging`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Software_package_(disambiguation)]`_`f

>>References

`:cite-note-bloch-1`!1.`! `F0af`_`[↑`#cite-ref-bloch-1-0]`_`f `:citerefbloch2008`a`F33f`_`[Bloch, Joshua`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Joshua_Bloch]`_`f (2008). `*Effective Java`* (Second ed.). Addison-Wesley. p. 13. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 978-0-321-35668-0.

>>External links

• Oracle's JavaBeans tutorials
• JavaBeans specification

`c`F0af`_`[↑ Back to top`#top]`_`f`a